﻿layui.use('table', function () {
    var table = layui.table;
    //方法级渲染
    table.render({
        elem: '#LAY_table_user'
        , url: '/Leave/GetLeaveAllMsg'
        , cols: [[
            { checkbox: true },
            { field: 'id', title: 'ID', width: 80, sort: true },
            { field: 'name', title: '假单名称', width: 120 }
        ]]
        , id: 'id'
        , page: false
        , height: 630
    });

    //搜索
    var $ = layui.$, active = {
        reload: function () {
            var demoReload = $('#leaveName');
            table.reload('id', {
                where: {
                    Name: demoReload.val()
                }
            });
        }
    };
    $('.demoTable .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    //新增
    $("div").delegate('#AddLeave', 'click', function () {
        layer.open({
            type: 2,
            title: "新建假单",
            area: ['1000px', '750px'],
            fixed: false, //不固定
            maxmin: true,
            shade: 0, //不遮挡
            id: 'addLeave',//防止重复弹出
            content: '/Leave/AddLeave',
            success: function (layero, index) {
                //layer.full(index);  //打开时最大化
            }
        });
    });
    //查看
    $("div").delegate('#SelectForm', 'click', function () {
        // 获取选中列数据
        var checkStatus = table.checkStatus('id');
        if (checkStatus.data.length === 0) {
            layer.alert("没有查看信息");
            return;
        }
        layer.open({
            type: 2,
            title: "查看表单",
            area: ['1000px', '750px'],
            fixed: false, //不固定
            maxmin: true,
            shade: 0, //不遮挡
            id: 'selectForm',//防止重复弹出
            content: '/Form/SeeForm?id=' + checkStatus.data[0].id,  // 只选择第一条
            success: function (layero, index) {
                //layer.full(index);  //打开时最大化
            }
        });
    });
});